package com.dpj.service;

import com.dpj.mapper.UserMapper;
import com.dpj.pojo.User;
import com.dpj.utils.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

public class UserService {
    SqlSessionFactory sessionFactory = SqlSessionFactoryUtils.getSessionFactory();
    public User selectByNameAndPassword(String username, String password) {
        SqlSession sqlSession = sessionFactory.openSession(true);
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        User user=mapper.selectByNameAndPassword(username,password);
        sqlSession.close();
        return user;
    }

    public void insertInto(String username, String password) {
        SqlSession sqlSession = sessionFactory.openSession(true);
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        sqlSession.close();
        mapper.insertInto(username,password);
    }

    public Boolean selectByName(String username) {
        SqlSession sqlSession = sessionFactory.openSession(true);
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);

        Boolean flag=mapper.selectByName(username);
        sqlSession.close();
        return flag;
    }
}
